<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta name="viewport" content="maximum-scale=1.0,minimum-scale=1.0,user-scalable=0,width=device-width,initial-scale=1.0" />
    <title>扫码支付</title>
    <link rel="stylesheet" type="text/css" href="../../css/api.css" />
    <link rel="stylesheet" type="text/css" href="../../css/style.css" />
    <link rel="stylesheet" type="text/css" href="../../css/aui.css" />
    <link rel="stylesheet" type="text/css" href="../../icon/iconfont.css" />
    <link rel="stylesheet" type="text/css" href="../../icon/font-awesome/css/font-awesome.min.css" />
    <style>
        .reset{
          background: #EEE;
        }
        .toptitle {
            text-align: center;
            margin: 2rem 0 0 0;
        }

        h2 {

            padding: 1rem 0 0 0;
        }

        .totalCash {
            padding: 2rem 0;
        }

        .price {
            padding: 0 7rem 0 1rem;
        }

        input.price {
            display: inline-block;
            width: 5rem;
            padding: 0 .5rem;
            height: 1rem;
        }
        /*优惠列表项*/

        .quan,
        .ji,
        .yue,
        .check {
            width: 40px;
            height: 40px;
            background-image: url('../../icon/icon.png');
            background-repeat: no-repeat;
            background-position: -55px -64px;
        }

        .ji {
            background-position: -55px -150px;
        }

        .yue {
            background-position: -55px -235px;
        }

        .check {
            background-position: -653px -149px;
        }

        .checked {
            background-position: -653px -236px !important;
        }

        .couponlist .item .choice {
            color: #777777 !important;
        }

        .couponlist .item {
            display: flex;
            padding: 1rem;
            align-items: center;
            justify-content: space-between;
        }

        .dateUse {
            color: #D39B51;
            font-size: 12px;
            padding: .5rem 0;
        }

        #payPost {
            font-size: 1rem;
            margin: 4rem 0;
            width: 100%;
            background: #D39B51;
            color: #fff;
            height: 2.5rem;
        }

        #totalprice {
            color: #D39B51;
        }

        #rechPost {
            font-size: 1rem;
            margin: 1rem 0;
            width: 50%;
            background: #D39B51;
            color: #fff;
            height: 2.5rem;
        }

        .ishidden {
            visibility: hidden;
        }

        .isshow {
            visibility: visible;
        }
        /*优惠券列表弹框*/

        .coupon-box,
        .notEnough,
        .usecoupon-box {
            position: fixed;
            top: 0;
            left: 0;
            right: 0;
            bottom: 0;
            z-index: 1;
            background: rgba(0, 0, 0, .6);
            display: none;
        }

        .coupon-box .list,
        .usecoupon-box .list {
            width: 80%;
            margin: 8rem auto 0 auto;
        }

        .coupon-box .list .aui-list-item-title {
            font-size: 14px !important;
        }

        .usecoupon-box .list .aui-list-item-title {
            font-size: 14px !important;
        }

        .itemli {
            margin: 10px 0 !important;
        }

        .cancel {
            color: #FFF;
            text-decoration: underline;
            display: inline-block;
            vertical-align: bottom;
            height: 2rem;
            margin: 0 0 0 1rem;
        }
        #reset{
          position: absolute;
          right: 1rem;
          top: 1.35rem;
          color:#D39B51;
        }

        .aui-radio:checked,
        .aui-radio.aui-checked,
        .aui-checkbox:checked,
        .aui-checkbox.aui-checked {
            background-color: #D2984D;
            border: solid 1px #D2984D;
        }
    </style>
</head>

<body>
    <div class="iconfont icon-fanhui" style="padding:10px;background:#FFF;border-bottom:1px solid #EEE;margin-top:20px;">
        <span onclick="api.closeWin();">&nbsp;支付</span>
    </div>
    <div calss="mainbox">
        <div class="toptitle">
            <p>欢迎光临</p>
            <h2 id="shopTitle"></h2>
        </div>
        <div class="totalCash">
            <label style="padding: 0 2rem;">消费金额</label>
            <em style="font-size:1.2rem;">&yen;</em>
            <input class="price" value="" name="totalprice" type="number" placeholder="输入金额" />元
        </div>
        <div class="couponlist" style="position:relative">
            <a id="reset" href="javascript:void(0)" class="ishidden"><i class="fa fa-times-circle"></i></a>
            <div class="item" id="hasCoupon" style="position: relative;">
                <span class="quan"></span>
                <div class="choice">选择可用优惠券</div>
                <label class="ishidden" id="couponValitem">抵扣 <em id="couponVal"></em>元</label>
                <span style="visibility: hidden;" class="check"></span>
            </div>

            <div class="item" id="jifenItem" style="display:none;">
                <span class="ji"></span>
                <div class="choice">可用积分 <em id="useJifen"></em></div>
                <label>抵扣 <em id="jianuseJifen"></em> 元</label>
                <span class="check"></span>
            </div>

            <div class="item" id="yueItem">
                <span class="yue"></span>
                <div class="choice">可用余额 <em id="useYue"></em></div>
                <label style="visibility: hidden;">抵扣 <em id="jianuseYue"></em> 元</label>
                <span class="check"></span>
            </div>

            <div class="aui-list-item-inner item">
                <label><input class="aui-radio" type="radio" name="paytype" data-type="wxpay">&nbsp;&nbsp;微信支付</label>
                <label style="margin-left:-5rem;"><input class="aui-radio" type="radio" name="paytype" data-type="alipay">&nbsp;&nbsp;支付宝支付</label>
            </div>
        </div>

        <div class="footer">
            <p style="text-align:right;padding:1rem;color:#000;display:none;">实付金额(&yen;)：
                <a id="totalprice" href="javascript:void(0);">0</a>
            </p>
            <button id="payPost" type="button" name="button">确认支付</button>
        </div>
    </div>

    <!-- 优惠券列表弹框 -->
    <div class="coupon-box">
        <div class="list">
            <ul class="aui-list aui-list-in couponList" style="height:15rem; overflow: auto;border-radius: 20px">
                <!-- 优惠券列表 -->
            </ul>
        </div>
    </div>


    <!-- 满足条件优惠券列表弹框 -->
    <div class="usecoupon-box">
        <div class="list">
            <ul class="aui-list aui-list-in UsecouponList" style="height:15rem; overflow: auto;border-radius: 20px">
                <!-- 满足条件优惠券列表 -->
            </ul>
        </div>
    </div>

    <!-- 余额不足立即充值 -->
    <div class="notEnough" style="text-align:center;">
        <p style="color: #FFF; margin: 13rem 0 1rem 0;">余额不足，请立即充值</p>
        <button id="rechPost" type="button" name="button">确认充值</button>
        <span class="cancel">取消</span>
    </div>


</body>
<script type="text/javascript" src="../../lib/zepto.js"></script>
<script type="text/javascript" src="../../script/api.js"></script>
<script type="text/javascript" src="../../script/dns.js"></script>
<script type="text/javascript" src="../../script/aui-toast.js"></script>

<script type="text/javascript" src="../../lib/artTemplate/template.js"></script>
<!-- 优惠券列表 -->
<script id="couponList" type="text/html">
    {{each data as value index}}
    <li class="aui-list-item itemli">
        <div class="aui-list-item-inner">
            <div class="aui-list-item-title">
                {{data[index].coupon.merchant.title}} {{data[index].coupon.title}}：￥{{data[index].coupon.face_value}}
                <div class="dateUse">{{data[index].coupon.day.str}}</div>
            </div>
        </div>

    </li>
    {{/each}}
</script>


<!-- 输入金额满足优惠券列表 -->
<script id="UsecouponList" type="text/html">
    {{each data as value index}}
    <li class="aui-list-item itemli canuseli" data-couponId="{{data[index].id}}" data-merchantId="{{data[index].coupon.id}}" data-couponVal="{{data[index].coupon.face_value}}" data-status="{{data[index].disable}}" onclick="ChoiceCoupon(this);">
        <div class="aui-list-item-inner">
            <div class="aui-list-item-title">
                {{data[index].coupon.merchant.title}} {{data[index].coupon.title}}：￥{{data[index].coupon.face_value}} {{if data[index].disable == '2'}}
                <div class="dateUse">该优惠券不可用:{{data[index].coupon.use_condition.msg}}</div>
                {{/if}}
            </div>
        </div>
    </li>
    {{/each}}
</script>

<script type="text/javascript">
    var merchantid;
    var toast = new auiToast({});
    var canuseYue;
    var dataCouponId;
    var dataMerchantId;
    var paytype = 0; //支付方式  0：余额支付（没选择微信支付或者支付宝支付） 1：微信支付  2：支付宝支付
    //选择优惠券抵扣
    function ChoiceCoupon(e) {
        var status = $(e).attr('data-status');
        if (status == 2) {
            api.toast({
                msg: '该优惠券不可用',
                duration: 2000,
                location: 'bottom' //'bottom'
            });
            return;
        } else {
            var currentCouponVal = $(e).attr('data-couponVal'); //当前优惠券的抵扣金额
            dataCouponId = $(e).attr('data-couponId'); //确认支付的时候要的优惠券id
            dataMerchantId = $(e).attr('data-merchantId'); //确认支付的时候要的优惠券id
            if (currentCouponVal) {
                $('.usecoupon-box').hide(); //隐藏优惠列表框
                $('#couponValitem').removeClass('ishidden');
                $('#reset').removeClass('ishidden');
                $("#couponVal").html(currentCouponVal); //赋值显示当前优惠券抵扣金额

                var totalprice = $("input[name='totalprice']").val();
                $('#totalprice').html((totalprice - currentCouponVal) < 0 ? '0' : (totalprice - currentCouponVal)); //输入总金额 - 当前优惠券的金额
                $('#jifenItem span').removeClass('checked'); //取消积分抵扣勾选
            }
        }
    }

    apiready = function() {
        //页面首次初始化--获取支付，优惠券等信息
        $('#couponValitem').addClass('ishidden');
          $('#reset').addClass('ishidden');
        // var mid = "YFWl92l7a5XEX8D6vIDGEiO0O0O2";//api.pageParam.mid;
        var mid = api.pageParam.mid;
        $.ajax({
            url: dns + 'pay/offline',
            type: 'GET',
            data: {
                'mid': mid
            },
            beforeSend: function(request) {
                request.setRequestHeader("token", localStorage.getItem('token'));
            },
            success: function(res) {
                console.log(JSON.stringify(res));
                if (res.code == '20000') {
                    if (res.data.user.point_deduction > 0) {
                        $('#jifenItem').show(); //判断是否有积分能抵扣
                    }
                    localStorage.setItem('mid', res.data.merchant.id);
                    merchantid = res.data.merchant.id;
                    $('#shopTitle').html(res.data.merchant.title == null ? '您的消费信息' : res.data.merchant.title);
                    $('#useJifen').html(res.data.user.integral);
                    $('#useYue').html(res.data.user.balance);
                    $('#jianuseJifen').html(res.data.user.integral);
                    $('#jianuseYue').html(res.data.user.balance);
                    canuseYue = res.data.user.balance;
                    //优惠券列表等信息
                    var html = template('couponList', {
                        data: res.data.coupon
                    });
                    if (!html) {

                        html = "<p class='get_coupon' style='text-align:center; margin:5rem 0;color:#F6B565'>暂无可用优惠券？立即领取</p>";
                        $('.couponList').html(html);
                        $('.get_coupon').click(function () {
                          api.openWin({
                              name: 'get_coupon',
                              url: '../frame0/gift-bag-lingqu.html',
                              pageParam: {
                                'merchantid': merchantid
                              } //页面代参数
                          });
                        });

                    } else {
                        $('.couponList').html(html);
                    }

                    //跳转确认充值
                    $('#rechPost').click(function() {
                        api.openWin({
                            name: 'money',
                            url: '../frame4/money/index.html',
                            pageParam: {
                                'yue': res.data.user.balance
                            } //页面代参数
                        });
                    });
                }
            },
        });
    }


    $(document).ready(function() {
        //消费金额输入
        $("input[name='totalprice']").keyup(function() {
            var currentPrice = $(this).val();
            $('#totalprice').html(currentPrice);
            //如果在重新输入金额的时候，隐藏优惠券/取消勾选抵扣
            $('#couponValitem').addClass('ishidden'); //输入金额不存在  隐藏优惠券抵扣显示
            $('#reset').addClass('ishidden');
            $("#jifenItem .check").removeClass('checked'); //输入金额不存在  取消余额勾选
            dataCouponId = 0;
            dataMerchantId = 0;
            if (!currentPrice) {
                $('#couponValitem').addClass('ishidden'); //输入金额不存在  隐藏优惠券抵扣显示
                  $('#reset').addClass('ishidden');
                $("#jifenItem .check").removeClass('checked'); //输入金额不存在  取消余额勾选
                dataCouponId = 0;
                dataMerchantId = 0;
            }
        });

        //是否选择优惠代扣
        $("#jifenItem .check").click(function() {
            var totalprice = $("input[name='totalprice']").val();
            if (!totalprice) {
                api.toast({
                    msg: '请输入消费金额',
                    duration: 2000,
                    location: 'bottom' //'bottom'
                });
                return;
            } else {
                $(this).hasClass('checked') ? $(this).removeClass('checked') : $(this).addClass('checked');
                //选择积分抵扣的时候
                if ($(this).hasClass('checked')) {
                    var jifenVal = $('#jianuseJifen').html();
                    var totalprice = $('#totalprice').html();
                    $('#totalprice').html((totalprice - jifenVal) < 0 ? '0' : (totalprice - jifenVal)); //输入总金额 - 当前积分的金额
                } else {
                    var jifenVal = $('#jianuseJifen').html();
                    var totalprice = $('#totalprice').html();
                    $('#totalprice').html((parseInt(totalprice) + parseInt(jifenVal)) < 0 ? '0' : (parseInt(totalprice) + parseInt(jifenVal))); //输入总金额 + 当前积分的金额
                }
            }
        });

        $("#yueItem .check").click(function() {
            $(this).hasClass('checked') ? $(this).removeClass('checked') : $(this).addClass('checked');
        });

        //打开优惠券弹窗
        $('#hasCoupon').click(function() {
            var totalprice = $("input[name='totalprice']").val();
            if (totalprice) {
                $.ajax({
                    url: dns + 'pay/select/coupon',
                    type: 'POST',
                    data: {
                        'mid': localStorage.getItem('mid'),
                        'total': totalprice
                    },
                    beforeSend: function(request) {
                        request.setRequestHeader("token", localStorage.getItem('token'));
                    },
                    success: function(res) {
                        if (res.code == '20000') {
                            //满足条件的优惠券列表等信息
                            if (res.data) {
                                var html = template('UsecouponList', {
                                    data: res.data
                                });
                                $('.UsecouponList').html(html);
                                $('.coupon-box').hide();
                                $('.usecoupon-box').show();
                            } else {
                                var html = "<p style='text-align:center; margin:5rem 0;color:#F6B565'>暂无可用优惠券？<br><br><br><br><span class='get_coupon' style='background:red;color:#FFF;padding:10px 2rem;border-radius:2px;'>立即领取</span></p>";
                                $('.UsecouponList').html(html);
                                $('.coupon-box').hide();
                                $('.usecoupon-box').show();

                                $('.get_coupon').click(function () {
                                    $('.usecoupon-box').hide();
                                  api.openWin({
                                      name: 'get_coupon',
                                      url: '../frame0/gift-bag-lingqu.html',
                                      pageParam: {
                                            'merchantid': merchantid
                                      } //页面代参数
                                  });
                                });

                            }
                        }
                    },
                });
            } else {
                api.toast({
                    msg: '请输入消费金额',
                    duration: 2000,
                    location: 'bottom' //'bottom'
                });
                return;
                // $('.coupon-box').show();
                // $('.usecoupon-box').hide();
            }
        });

        //重置优惠券选择
        $('#reset').click(function(){
          $(this).addClass('ishidden');
          $('#couponValitem').addClass('ishidden');
        })

        //关闭余额不足
        $('.cancel').click(function() {
            $('.notEnough').hide();
        });

        //关闭优惠券弹窗
        $('.usecoupon-box').click(function(e) {
            var target = $(e.target);
            if (target.is('.usecoupon-box')) {
                $(this).hide();
            };
        });

        $("input[name='paytype']").click(function() {
            var status = $(this).data('type');
                if (status == 'wxpay') {
                    //serverWXPay(amount); //微信支付
                    paytype = 1;
                }else{
                  //  serverAlipay(amount); //支付宝支付
                  paytype = 2;
                }
        });


        //确认支付
        $('#payPost').click(function() {
          //  var mid = api.pageParam.mid
            var systemType = api.systemType //判断设备是 android 还是 iOS
            var order; //订单号
            var payPrice = $("input[name='totalprice']").val(); //消费金额
            var amount = $("#totalprice").text(); //实付金额

            if (!dataCouponId || !dataMerchantId) {
                dataCouponId = 0;
                dataMerchantId = 0;
            }
            if ($('#jifenItem .check').hasClass('checked')) {
                var isintegral = "1";
            } else {
                var isintegral = "0";
            }

            if ($('#yueItem .check').hasClass('checked')) {
                var isbalance = "1";
            } else {
                var isbalance = "0";
            }

            var dataList = {
                'total': payPrice,
                'mid': localStorage.getItem('mid'),
                'cid': dataCouponId + ',' + dataMerchantId,
                'is_integral': isintegral,
                'is_balance': isbalance,
                'type':paytype
            }
            if (!payPrice) {
                api.toast({
                    msg: '请输入消费金额',
                    duration: 2000,
                    location: 'bottom' //'bottom'
                });
                return;
            }

            Paypost(dataList,paytype);  //确认支付

        });
    })

    //确认支付
    function Paypost(data,paytype) {
        if(paytype == 1) {  //微信支付
          $('#payPost').attr('disabled','disabled');
          serverWXPay(data);
        };
        if(paytype == 2) { // 支付宝支付
          $('#payPost').attr('disabled','disabled');
          serverAlipay(data);
        };
        if(paytype == 0) {
         // 余额支付或者积分支付
        $('#payPost').attr('disabled','disabled');
          $.ajax({
              url: g_serverApi + 'v2/pay/confirmorder',
              type: 'POST',
              dataType: 'json',
              data: data,
              beforeSend: function(request) {
                  request.setRequestHeader("token", localStorage.getItem('token'));
              },
              success: function(msg) {
                  if (msg.code == '20000') {
                    console.log(JSON.stringify(msg));
                    if(msg.msg != '支付成功'){
                      api.toast({
                          msg: msg.msg,
                          duration: 2000,
                          location: 'bottom' //'bottom'
                      });
                      $('#payPost').removeAttr('disabled');
                      return;
                    }

                    api.toast({
                        msg: msg.msg,
                        duration: 2000,
                        location: 'bottom' //'bottom'
                    });
                      setTimeout(function() {
                        $("input[name='totalprice']").val('');
                        $('#jifenItem .check').removeClass('checked');
                        $('#yueItem .check').removeClass('checked');
                        $('#payPost').removeAttr('disabled');
                          api.openWin({
                              name: 'banner',
                              url: '../frame4/order/index.html',
                              pageParam: {'pay':'ispay'}, //页面代参数
                          });
                      }, 1500)
                  }
              },
              error: function(err) {
                  api.toast({
                      msg: JSON.parse(err.responseText).msg,
                      duration: 2000,
                      location: 'bottom' //'bottom'
                  });
                  return;
              }
          });
        }

    }


      // 服务器支付宝预订单支付
      function serverAlipay(data) {
          $.ajax({
              url: g_serverApi + 'v2/pay/confirmorder',
              type: "POST",
              data:data,
              dataType: 'json',
              beforeSend: function(request) {
                  request.setRequestHeader("token", localStorage.getItem('token'));
              },
              success: function(res) {　　
                   console.log(JSON.stringify(res));　
                  // 调取apicloud 支付功能
                  if(res.msg == '支付成功'){
                    toast.success({
                        title: "支付成功",
                        duration: 2000
                    });
                    setTimeout(function() {
                      $("input[name='totalprice']").val('');
                      $('#jifenItem .check').removeClass('checked');
                      $('#yueItem .check').removeClass('checked');
                      $('#payPost').removeAttr('disabled');
                        api.openWin({
                            name: 'banner',
                            url: '../frame4/order/index.html',
                            pageParam: {'pay':'ispay'}, //页面代参数
                        });
                    }, 1500)
                  }else{
                    AliPay(res);
                  }

              },
              error: function(err) {
                  toast.fail({
                      title: "请重新发起支付",
                      duration: 2000
                  });
                    $('#payPost').removeAttr('disabled');
                  return;
              }
          });
      }
      // apiCloud支付宝支付
      function AliPay(serverData) {
          var aliPay = api.require('aliPay');
          aliPay.config({
              partner: serverData.data.partner,
              seller: serverData.data.seller,
              rsaPriKey: serverData.data.rsaPriKey,
              rsaPubKey: serverData.data.rsaPubKey,
              notifyURL: serverData.data.notify_url
          }, function(ret, err) {
              if (ret.status) {
                  aliPay.pay({
                      subject: serverData.data.subject,
                      body: serverData.data.body,
                      amount: serverData.data.total_fee,
                      tradeNO: serverData.data.out_trade_no,
                  }, function(ret, err) {
                    if(ret.code=="9000"){
                      toast.success({
                          title: "支付成功!",
                          duration: 2000
                      });
                      setTimeout(function() {
                        $("input[name='totalprice']").val('');
                        $('#jifenItem .check').removeClass('checked');
                        $('#yueItem .check').removeClass('checked');
                        $('#payPost').removeAttr('disabled');
                          api.openWin({
                              name: 'banner',
                              url: '../frame4/order/index.html',
                              pageParam: {'pay':'ispay'}, //页面代参数
                          });
                      }, 1500)
                    }else{
                      toast.fail({
                          title: "支付失败!",
                          duration: 2000
                      });
                        $('#payPost').removeAttr('disabled');
                    }
                  });
              } else {
                 api.alert({
                   title: '支付结果',
                   msg: err.msg,
                   buttons: ['确定']
                 });
            }
          });

      }

      // 服务器微信预订单支付
      function serverWXPay(data) {
          $.ajax({
              url: g_serverApi + 'v2/pay/confirmorder',
              type: "POST",
              data:data,
              dataType: 'json',
              beforeSend: function(request) {
                  request.setRequestHeader("token", localStorage.getItem('token'));
              },
              success: function(res) {　　
                   //console.log(JSON.stringify(res));　
                  // 调取apicloud 支付功能
                  if(res.msg == '支付成功'){
                    toast.success({
                        title: "支付成功",
                        duration: 2000
                    });
                    setTimeout(function() {
                      $("input[name='totalprice']").val('');
                      $('#jifenItem .check').removeClass('checked');
                      $('#yueItem .check').removeClass('checked');
                      $('#payPost').removeAttr('disabled');
                        api.openWin({
                            name: 'banner',
                            url: '../frame4/order/index.html',
                            pageParam: {'pay':'ispay'}, //页面代参数
                        });
                    }, 1500)
                  }else{
                    Wxpay(res);
                  }
              },
              error: function(err) {
                  toast.fail({
                      title: "请重新发起支付",
                      duration: 2000
                  });
                    $('#payPost').removeAttr('disabled');
                  return;
              }
          });
      }
      // apiCloud微信支付
      function Wxpay(serverData) {
          var wxPay = api.require('wxPay');
          wxPay.config({
              apiKey: serverData.data.apiKey,
              mchId: serverData.data.mchId,
              partnerKey: serverData.data.partnerKey,
              notifyUrl: serverData.data.notifyUrl
          }, function(ret, err) {
              if (ret.status) {
                  wxPay.pay({
                      description: serverData.data.description,
                      totalFee: serverData.data.totalFee,
                      tradeNo: serverData.data.tradeNo
                  }, function(ret, err) {
                      // 用户正常行为点击了 返回商户 按钮
                      if (ret.status) {
                          toast.success({
                              title: "支付成功",
                              duration: 1500
                          });
                          setTimeout(function() {
                            $("input[name='totalprice']").val('');
                            $('#jifenItem .check').removeClass('checked');
                            $('#yueItem .check').removeClass('checked');
                            $('#payPost').removeAttr('disabled');
                              api.openWin({
                                  name: 'banner',
                                  url: '../frame4/order/index.html',
                                  pageParam: {'pay':'ispay'}, //页面代参数
                              });
                          }, 1500)
                      } else {
                          toast.fail({
                              title: "支付失败",
                              duration: 2000
                          });
                            $('#payPost').removeAttr('disabled');
                          return;
                      }
                  });
              } else {
                  toast.success({
                      title: "支付失败",
                      duration: 1500
                  });
                  setTimeout(function() {
                      $('#payPost').removeAttr('disabled');
                      api.closeWin();
                  }, 2000)

                  return;
              }
              // 心跳查询该笔订单
              var orderStatus = setInterval(function() {
                  getOrderStatus(serverData.data.tradeNo)
              }, 1000);
          });
      }

      // 查询订单支付状态
      function getOrderStatus(order_no) {
          $.ajax({
              url: g_serverApi + 'va2/pay/status?order=' + order_no,
              type: "GET",
              dataType: 'json',
              beforeSend: function(request) {
                  request.setRequestHeader("token", localStorage.getItem('token'));
              },
              success: function(res) {　　
                  // clearInterval(orderStatus)
                  toast.success({
                      title: "支付成功",
                      duration: 1500
                  });
                  setTimeout(function() {
                      api.closeWin()
                  }, 2000)
              },
              error: function(err) {
                  toast.loading({
                      title: "请稍候",
                      duration: 2000
                  }, function(ret) {

                  });
                  return;
              }
          });
      }
</script>

</html>
